<template>
  <div class="post-card">
    <div class="post-header">
      <div class="user-info">
        <van-image :src="post.userAvatar" round fit="cover" class="avatar" />
        <div class="user-details">
          <span class="user-name">{{ post.userName }}</span>
          <span class="post-time">{{ post.postTime }}</span>
        </div>
      </div>
      <van-icon name="ellipsis" class="post-options" />
    </div>

    <div class="post-content">
      <p class="post-text">{{ post.text }}</p>
      <div v-if="post.images && post.images.length" class="post-images">
        <van-image
            v-for="img in post.images"
            :key="img"
            :src="img"
            fit="cover"
            class="post-image"
            lazy-load
        />
      </div>
    </div>

    <div class="post-actions">
      <div class="action-item">
        <van-icon name="like" />
        <span>{{ post.likes }}</span>
      </div>
      <div class="action-item">
        <van-icon name="comment" />
        <span>{{ post.comments }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';

defineProps({
  post: {
    type: Object,
    required: true,
    default: () => ({
      userAvatar: 'https://placehold.co/40x40/E8F0FF/3A7BFF.png?text=A',
      userName: '用户名',
      postTime: '2小时前',
      text: '这是一个帖子的内容。',
      images: [],
      likes: 0,
      comments: 0
    })
  }
});
</script>

<style scoped>
.post-card {
  background-color: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 15px;
  margin-bottom: 20px;
}

.post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.user-info {
  display: flex;
  align-items: center;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  color: var(--text-dark);
}

.post-time {
  font-size: 12px;
  color: var(--text-light);
}

.post-options {
  color: var(--text-light);
  cursor: pointer;
}

.post-content {
  margin-bottom: 15px;
}

.post-text {
  color: var(--text-medium);
  line-height: 1.6;
}

.post-images {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.post-image {
  width: 100%;
  height: 100px;
  border-radius: 8px;
}

.post-actions {
  display: flex;
  justify-content: flex-start;
  gap: 20px;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.action-item {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text-medium);
  cursor: pointer;
}

.action-item .van-icon {
  margin-right: 5px;
  font-size: 18px;
}
</style>